package sortStudy;

public class QuickSort {

    /**
     * 快速排序
     * @param args
     */
    public static void main(String[] args) {
        int[] nums = new int[]{2, 1, 7, 9, 4, 6, 8, 3};
        quickSort(nums, 0, nums.length - 1);
        for (int i = 0; i < nums.length; i++){
            System.out.println(nums[i]);
        }
    }

    public static void quickSort(int[] nums, int l, int r){
        if (l >= r){
            return;
        }
        int first = l, last = r;
        int key = nums[first];
        while (first < last){
            while (first < last && nums[last] >= key){
                last--;
            }
            nums[first] = nums[last];
            while (first < last && nums[first] <= key){
                first++;
            }
            nums[last] = nums[first];
        }
        nums[first] = key;
        quickSort(nums, l, first - 1);
        quickSort(nums, first + 1, r);
    }
}
